<template>
  <dv-scroll-board :config="chartConfig" style="height: 100%;width: 100%;"/>
</template>
<script>
import {defineComponent, reactive, toRefs} from "vue";
//轮播表
export default defineComponent({
  name: 'dv-chart-scroll-table',
  props: {
    workBook: {type: Object}
  },
  setup() {
    const state = reactive({
      chartConfig: {
        data: [],
        index: true,
        columnWidth: [50],
        align: ['center'],
        headerBGC:'#100C2A4D',
        oddRowBGC:'#F4F6FA52',
        evenRowBGC:'#39436A36'
      }
    })
    /**
     * 图表实现方法
     * @param data 数据
     * @param columnFields 列字段
     * @param rowFields 行字段
     * @param chartMode 图表类型
     * @param options 配置项
     */
    const build = (data, columnFields, rowFields, chartMode, options) => {
      return new Promise((resolve, reject) => {
        let data1 = []
        //列维度
        let colDimension = columnFields.filter(d => d.slaveType === 0);
        //列维度值
        // let cols = data.map(t => t[colDimension.name])
        if(columnFields){
          state.chartConfig.header = columnFields.map(d=>d.name)
        }

        data.forEach(d=>{
          let curr = []
          for(let j = 0;j<columnFields.length;j++){
            curr.push(d[columnFields[j].name])
          }
          data1.push(curr)
        })



        // if (cols.length > 0) {
        //   state.chartConfig.header = cols
        // }
        // //行度量
        // let rowMeasure = rowFields.find(d => d.slaveType === 1);
        // //行维度
        // let rowDimension = rowFields.find(d => d.slaveType === 0);
        //
        // if (rowDimension) {
        //   //行维度值
        //   let rows = data.map(t => t[rowDimension.name])
        //   for (let i = 0; i < rows.length; i++) {
        //     let curr = [rows[i]]
        //     for(let j = 0;j<cols.length;j++){
        //       let currData = data.find(item=>item[rowDimension.name]==rows[i]&&item[colDimension.name]==cols[j])
        //       curr.push(currData[rowMeasure.name])
        //     }
        //     data1.push(curr)
        //   }
        // }else{
        //   let curr = []
        //   for(let j = 0;j<cols.length;j++){
        //     let currData = data.find(item=>item[colDimension.name]==cols[j])
        //     curr.push(currData[rowMeasure.name])
        //   }
        //   data1.push(curr)
        // }

        state.chartConfig.data = data1
        state.chartConfig = {...state.chartConfig}
        resolve({})
      })
    }

    return {
      build, ...toRefs(state)
    }
  }
})
</script>
